/**
 * Description: RegisterLateAction.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Apr 4, 2009 1:33:46 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.web.action.registerinfo;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.paradise.dms.pojo.RegisterLate;
import org.paradise.dms.services.RegisterLateService;
import org.paradise.dms.web.action.DMSBaseAction;
import org.paradise.dms.web.tools.Pager;
import org.paradise.dms.web.tools.PagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Apr 4, 2009 1:33:46 PM 李萌（neolimeng@gmail.com）created
 */
@Service
public class RegisterLateAction extends DMSBaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8181635573990512288L;
	private static Logger log = Logger.getLogger(RegisterLateAction.class);
	@Autowired
	@Qualifier("registerLateServiceImpl")
	private RegisterLateService registerLateService;

	private RegisterLate rl;
	private List<RegisterLate> rll;

	@Autowired
	private PagerService pagerService;
	private Pager pager;
	protected String currentPage;
	protected String totalRows;
	protected String pagerMethod;

	public String insertRegisterLate() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String recorderId = (String) session.getAttribute("systemuserid");
		String recorderName = (String) session.getAttribute("systemusername");
		log.info("DMS_info_用户操作，操作者ID为" + recorderId);
		rl.setRecordby(recorderName);
		rl.setRegisterlateind(1);
		rl.setRegisterlatetime(new Date());
		if (this.registerLateService.insertRegisterLate(rl)) {
			return SUCCESS;
		} else
			return INPUT;
	}

	public String updateRegisterLate() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		String recorderId = (String) session.getAttribute("systemuserid");
		String recorderName = (String) session.getAttribute("systemusername");
		log.info("DMS_info_用户操作，操作者ID为" + recorderId);
		rl.setRecordby(recorderName);
		rl.setRegisterlateind(1);
		rl.setRegisterlatetime(new Date());
		if (this.registerLateService.updateRegisterLate(rl))
			return SUCCESS;
		else
			return INPUT;
	}

	public String deleteRegisterLate() {
		int rlid = Integer.parseInt(ServletActionContext.getRequest().getParameter("registerlateid"));
		if (this.registerLateService.deleteRegisterLate(rlid))
			return SUCCESS;
		else
			return INPUT;
	}

	public String getRegisterLate() {
		try {
			int rlid = Integer.parseInt(ServletActionContext.getRequest().getParameter("registerlateid"));
			rl = this.registerLateService.getRegisterLate(rlid);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String getAllRegisterLate() {
		try {
			rll = this.registerLateService.getAllRegisterLate();
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	public String listAllRegisterLate() {
		try {
			int totalRow = this.registerLateService.getAllRows();
			pager = pagerService.getPager(this.getCurrentPage(), this.getPagerMethod(), totalRow);
			this.setCurrentPage(String.valueOf(pager.getCurrentPage()));
			this.setTotalRows(String.valueOf(totalRow));
			rll = this.registerLateService.listAllRows(pager.getPageSize(), pager.getStartRow());
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return INPUT;
		}
	}

	/**
	 * @return the registerLateService
	 */
	public RegisterLateService getRegisterLateService() {
		return registerLateService;
	}

	/**
	 * @param registerLateService
	 *            the registerLateService to set
	 */
	public void setRegisterLateService(RegisterLateService registerLateService) {
		this.registerLateService = registerLateService;
	}

	/**
	 * @return the rl
	 */
	public RegisterLate getRl() {
		return rl;
	}

	/**
	 * @param rl
	 *            the rl to set
	 */
	public void setRl(RegisterLate rl) {
		this.rl = rl;
	}

	/**
	 * @return the rll
	 */
	public List<RegisterLate> getRll() {
		return rll;
	}

	/**
	 * @param rll
	 *            the rll to set
	 */
	public void setRll(List<RegisterLate> rll) {
		this.rll = rll;
	}

	public PagerService getPagerService() {
		return pagerService;
	}

	public void setPagerService(PagerService pagerService) {
		this.pagerService = pagerService;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public String getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(String currentPage) {
		this.currentPage = currentPage;
	}

	public String getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(String totalRows) {
		this.totalRows = totalRows;
	}

	public String getPagerMethod() {
		return pagerMethod;
	}

	public void setPagerMethod(String pagerMethod) {
		this.pagerMethod = pagerMethod;
	}
}
